<?php 
require_once (__DIR__ . "/../../models/Keywords.php");

if(isset($_POST['id']))
{
	$row = $_POST;
	$response = Keywords::Validate($row);
	if ($response === true)
			$response = Keywords::Insert($row);
	if($response === true)
		header("Location: $rootUrl/../W/Keywords/index");
}

?>
				<?php if(isset($response)): ?>
					<dl class="dl-horizontal error">
						<?php foreach ($response as $key => $value): ?>
							<dt><?php echo $key?></dt>
							<dd><?php echo $value?></dd>
						<?php endforeach; ?>						
					</dl>
				<?php endif; ?>
				<form class="form-horizontal" action="" method="post">
					<input type="hidden" name="id" value="" />
					<div class="control-group">
						<label class="control-label" for="name">Name:</label>
						<div class="controls">
							<input type="text" name="name" id="name" value="" 
class="<?php echo isset($response['name']) ? 'error' : '' ?>"
								/>
								<?php if(isset($response['name'])): ?>
									<span class="error"><?php echo $response['name']?></span>
								<?php endif; ?>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label" for="parent_id">Parent Id:</label>
						<div class="controls">
<?php $results = Keywords::GetAll(); 
							echo '<select name="parent_id">';
	  while($row2 = $results->fetch_assoc()): 
				echo '<option value="'.$row2['id'].'" >'.$row2['name'].'</option>';					
	  endwhile;	
	   						echo '</select>';
						?> 
						</div>
					</div>
					<div class="control-group">
						<div class="controls">
							<input type="submit" value="Save" class="btn btn-primary" />
						</div>
					</div>
			
				</form>